package com.infodms.dms.actions.sales.storageManage;

import java.sql.ResultSet;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.materialManager.MaterialGroupManagerDao;
import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.dao.sales.dealer.DealerInfoDao;
import com.infodms.dms.dao.sales.storageManage.CheckVehicleDAO;
import com.infodms.dms.dao.sales.storageManage.VehicleDispatchDAO;
import com.infodms.dms.dao.sales.storageManage.VehicleLocationChangeDAO;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TmDealerPO;
import com.infodms.dms.po.TmVehiclePO;
import com.infodms.dms.po.TtVsVehicleTransferChkPO;
import com.infodms.dms.po.TtVsVehicleTransferPO;
import com.infodms.dms.po.TtVsVhclChngPO;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.ActionContextExtend;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;

public class VehicleDispatch extends BaseDao{
	public Logger logger = Logger.getLogger(VehicleDispatch.class);
	private ActionContext act = ActionContext.getContext();
	private static final CheckVehicleDAO dao = new CheckVehicleDAO ();
	public static final CheckVehicleDAO getInstance() {
		return dao;
	}
	
	private final String  VehicleDispatchInitUrl = "/jsp/sales/storageManage/vehicleDispatchInit.jsp";
	private final String  vehicleDispatchCheckOEMInit = "/jsp/sales/storageManage/vehicleDispatchCheckOEMInit.jsp";
	
	/**
	 * FUNCTION		:	调拨申请页面初始化(DLR)
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-5-27
	 */
	public void VehicleDispatchInit(){
		AclUserBean logonUser = null;
		try {
			ActionContextExtend atx = (ActionContextExtend) ActionContext.getContext();
			String reqURL = atx.getRequest().getContextPath();
			if("/CVS-SALES".equals(reqURL.toUpperCase())){
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
			}
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			warehouseList();
			getSecodeDel_D() ;
			String dlrId = logonUser.getDealerId() ;
			
			Integer oemFlag = CommonUtils.getNowSys(Long.parseLong(logonUser.getOemCompanyId())) ;
			
			act.setOutData("oemFlag", oemFlag) ;
			act.setOutData("dlrId", dlrId) ;
			act.setForword(VehicleDispatchInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "调拨申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	} 
	/**
	 * FUNCTION		:	经销商仓库位置下拉列表
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-7-20
	 */
	public void warehouseList() {
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			String warehouseType = act.getRequest().getParamValue("warehouseType") ;
			if (warehouseType == null || warehouseType.equals("")) {
				warehouseType = "" ;
			}
			Long poseId = logonUser.getPoseId();
			Long comId = logonUser.getCompanyId() ;
			List<Map<String, Object>> areaList = MaterialGroupManagerDao
					.getDealerId(comId.toString(),poseId.toString());
			String dealerIds__ = "";
			for(int i=0; i<areaList.size();i++) {
				dealerIds__ += areaList.get(i).get("DEALER_ID").toString()+"," ;
			}
			if (!"".equals(dealerIds__)) {
				dealerIds__ = dealerIds__.substring(0,(dealerIds__.length()-1)) ;
			} else {
				dealerIds__ = "" ;
			}
			List<Map<String,Object>> list = VehicleLocationChangeDAO.warehouseQuery(dealerIds__,"") ;
			act.setOutData("list", list) ;
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "当前经销商用户仓库查询失败");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/*
	 * FUNCTION	: 获取当前用户下的所有二级经销商：下拉列表使用
	 */
	public void getSecodeDel_D() {
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			Long poseId = logonUser.getPoseId();
			Long comId = logonUser.getCompanyId() ;
			List<Map<String, Object>> areaList = MaterialGroupManagerDao
					.getDealerId(comId.toString(),poseId.toString());
			String dealerIds__ = "";
			for(int i=0; i<areaList.size();i++) {
				dealerIds__ += areaList.get(i).get("DEALER_ID").toString()+"," ;
			}
			if (!"".equals(dealerIds__)) {
				dealerIds__ = dealerIds__.substring(0,(dealerIds__.length()-1)) ;
			} else {
				dealerIds__ = "" ;
			}
			
			List<Map<String, Object>> secondeDels = DealerInfoDao.getInstance().getDel("",dealerIds__,Constant.DEALER_LEVEL_02.toString(), Constant.DEALER_TYPE_DVS+"") ;
			act.setOutData("secondeDels", secondeDels) ;
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "当前经销商用户下级经销商查询失败");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * FUNCTION		:	调拨申请：查询展示(DLR)
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-5-27
	 */
	public void VehicleDispatchList(){
		AclUserBean logonUser = null;
		try {
			RequestWrapper request = act.getRequest();
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			
			String materialCode = CommonUtils.checkNull(request.getParamValue("materialCode"));		//物料组
			String materialCode__ = CommonUtils.checkNull(request.getParamValue("materialCode__")); //物料
			String vin =  CommonUtils.checkNull(request.getParamValue("vin"));
			String warehouseId = CommonUtils.checkNull(request.getParamValue("warehouse__"));
			Long poseId = logonUser.getPoseId();
			Long comId = logonUser.getCompanyId() ;
			List<Map<String, Object>> areaList = MaterialGroupManagerDao
					.getDealerId(comId.toString(),poseId.toString());
			String dealerIds__ = "";
			for(int i=0; i<areaList.size();i++) {
				dealerIds__ += areaList.get(i).get("DEALER_ID").toString()+"," ;
			}
			dealerIds__ = dealerIds__.substring(0,(dealerIds__.length()-1)) ;				//当前用户职位对应的经销商ID
			
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			PageResult<Map<String, Object>> ps = VehicleDispatchDAO.getCanDispatchVehicleList(warehouseId,dealerIds__,materialCode,materialCode__, vin, Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
		}  catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "调拨申请：查询展示");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * FUNCTION		:	调拨申请：提交(DLR)
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-5-31
	 */
	public void vehicleDispatchSubmit(){
		AclUserBean logonUser = null;
		try {
			RequestWrapper request = act.getRequest();
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			String vehicleIds = request.getParamValue("vehicleIds");	
			String[] vehicleId = vehicleIds.split(",");										//要调拨的车辆id
			String dealerId__A = CommonUtils.checkNull(request.getParamValue("dealerId"));	//接收车辆的dealerId
			TmDealerPO tdp = new TmDealerPO() ;
			tdp.setDealerId(Long.parseLong(dealerId__A)) ;
			List<TmDealerPO> listC = dao.select(tdp) ;
			Long oemComId = new Long(0) ;
			if (listC != null && listC.size() > 0) {
				oemComId = listC.get(0).getOemCompanyId() ;
			}
			List<Map<String, Object>> codeList = DealerInfoDao.getInstance().getDel(dealerId__A, "", "", "") ;
			String dealerCode = "" ;
			if (codeList != null && codeList.size() > 0) {
				dealerCode = codeList.get(0).get("DEALER_CODE").toString() ;	//接收车辆的dealerCode
			}
			//得到经销商级别
			List<Map<String, Object>> arealist = VehicleDispatchDAO.selectAreaId(dealerCode);
			String str = "";
			String myVinStr="";//返回检索数据验证字符串
			for (int i = 0; i < vehicleId.length; i++){
				myVinStr=VehicleDispatchDAO.getVinRightCar(vehicleId[i]);
				if(myVinStr!=""){
					myVinStr="VIN码为"+myVinStr+"的车辆当前位置不存在，请在车辆位置变更中为该车设置当前位置";
					break;
				}
				
				boolean areaFlag = false;
				// List<Map<String, Object>> vhcllist = VehicleDispatchDAO.selectVehicleAreaId(vehicleId[i]);
				
				List<Map<String, Object>> vhcllist = VehicleDispatchDAO.selectVehicleAreaId(Long.parseLong(vehicleId[i])) ;
				String vin ="";
				for(int n = 0;n<vhcllist.size();n++){
					String vareaId = vhcllist.get(n).get("AREA_ID").toString();
					 vin = vhcllist.get(n).get("VIN").toString();
					for(int m=0; m<arealist.size() && areaFlag == false; m++){
						String areaId = arealist.get(m).get("AREA_ID").toString();
						if(vareaId.equals(areaId)){
							areaFlag=true;
							break ;
						}else{
							areaFlag=false;
						}
					}
					if(areaFlag) {
						break ;
					}
				}
				if(areaFlag==false){
					if("".equals(str)){
						str = vin;
					}else{
						str = vin+","+str;
					}
				}
			}
			if(myVinStr!=""){
				act.setOutData("returnValue", 3);
				act.setOutData("myVinStr", myVinStr);
			}
			else if(str.length()>0){
				act.setOutData("returnValue", 2);
				act.setOutData("str", str);
			}else{
				String transfer_reason = CommonUtils.checkNull(request.getParamValue("transfer_reason"));		//调拨原因
				/*if (null != transfer_reason && !"".equals(transfer_reason)) {
					transfer_reason = new String(transfer_reason.getBytes("ISO-8859-1"),"GB2312");
				}*/
				if (null != vehicleIds && vehicleId.length>0) {
					
					for (int i = 0; i < vehicleId.length; i++) {
						TtVsVehicleTransferPO transferPO = new TtVsVehicleTransferPO();
						Long transferId = Long.parseLong(SequenceManager.getSequence(""));
						String transferNo = "PF" +transferId ;							//批发号
						transferPO.setTransferId(transferId);							//调拨ID
						transferPO.setTransferNo(transferNo) ;
						transferPO.setVehicleId(Long.parseLong(vehicleId[i])); 			//车辆ID
						//通过TM_VEHICLE得到dealerID
						TmVehiclePO vehiclePO = new TmVehiclePO();
						vehiclePO.setVehicleId(Long.parseLong(vehicleId[i]));
						List vehicelList = dao.select(vehiclePO);
						Long dealerId = ((TmVehiclePO)vehicelList.get(0)).getDealerId();
						transferPO.setOutDealerId(dealerId);     						//调出经销商ID
						transferPO.setTransferDate(new Date());							//调拨日期
						transferPO.setCompanyId(oemComId) ;
						if (null != transfer_reason && !"".equals(transfer_reason)) {
							transferPO.setTransferReason(transfer_reason.trim());		//调拨原因
						}else{
							transferPO.setTransferReason(" ");
						}
						transferPO.setCheckStatus(Constant.DISPATCH_STATUS_01); 		//审核状态
						TmDealerPO dealerPO = new TmDealerPO();
						dealerPO.setDealerCode(dealerCode);
						List list = dao.select(dealerPO);
						if (null != list && list.size()>0) {
							Long dealerID = ((TmDealerPO)list.get(0)).getDealerId();
							transferPO.setInDealerId(dealerID);				   			//调入经销商ID
							
							transferPO.setCreateDate(new Date());
							transferPO.setCreateBy(logonUser.getUserId());
							
							boolean isRelation = false;
							/*String logonDealerId = logonUser.getDealerId();
							
							//得到调入经销商的parentDealerId
							Map<String, Object> D_ParentDealerId__ = VehicleDispatchDAO.getParentDealerId(dealerID+"");
							String D_ParentDealerId = D_ParentDealerId__.get("PARENT_DEALER_D").toString();
							
							String[] logonIds = logonDealerId.split(",");
							for (int j = 0; j < logonIds.length; j++) {
								if (logonIds[j].equals(D_ParentDealerId)) {
									isRelation = true;
									break;
								}
							}*/
							// 验证两个经销商dealerId是否属于同一经销商级别树
							if(VehicleDispatchDAO.chkDlr(dealerID.toString(), dealerId.toString()) || VehicleDispatchDAO.chkDlr(dealerId.toString(), dealerID.toString())) {
								isRelation = true ;
							}
							
							if (isRelation) {
								//直接修改dealerId
								TmVehiclePO tmVehiclePO__ = new TmVehiclePO();
								tmVehiclePO__.setVehicleId(Long.parseLong(vehicleId[i]));
								List<TmVehiclePO> listB = dao.select(tmVehiclePO__) ;
								Long dealerIdA = listB.get(0).getDealerId();			//调出方
								transferPO.setCheckStatus(Constant.DISPATCH_STATUS_03);
								dao.insert(transferPO);
								//判断是否是结算中心
								
								TmDealerPO tmDealerPO = new TmDealerPO();
								tmDealerPO.setDealerId(dealerIdA);
								List dealerList = dao.select(tmDealerPO);
								Integer dealerType = ((TmDealerPO)dealerList.get(0)).getDealerType();
								if (dealerType == Constant.DEALER_TYPE_JSZX) {
									List<Object> ins = new LinkedList<Object>();
									ins.add(transferId);
									List<Integer> outs = new LinkedList<Integer>();
									dao.callProcedure("P_VEHICLE_TRANSFERDATA_TO_ERP", ins, outs);
								}
								TmVehiclePO tmVehiclePO__value = new TmVehiclePO();
								tmVehiclePO__value.setVehicleId(Long.parseLong(vehicleId[i]));
								tmVehiclePO__value.setDealerId(dealerID);
								tmVehiclePO__value.setStorageDate(new Date()) ;
								tmVehiclePO__value.setVehicleArea("");
								dao.update(tmVehiclePO__, tmVehiclePO__value);
							}else{
								dao.insert(transferPO);
							}
						}
						
						
						
						//向日志表写入操作记录
						TtVsVhclChngPO chngPO = new TtVsVhclChngPO();
						Long vhclChangeId = Long.parseLong(SequenceManager.getSequence(""));
						chngPO.setVhclChangeId(vhclChangeId);				//改变序号
						chngPO.setVehicleId(Long.parseLong(vehicleId[i]));	//车辆ID
						chngPO.setOrgType(logonUser.getOrgType());			//组织类型
						chngPO.setOrgId(logonUser.getOrgId());				//组织ID
						chngPO.setDealerId(dealerId);						//经销商ID
						chngPO.setChangeCode(Constant.STORAGE_CHANGE_TYPE); //改变类型
						chngPO.setChangeName(Constant.STORAGE_CHANGE_TYPE_08+"");//改变名称
						chngPO.setChangeDate(new Date());					//改变时间
						if (null != transfer_reason && !"".equals(transfer_reason)) {
							chngPO.setChangeDesc(transfer_reason);			//改变描述
						}
						
						chngPO.setCreateDate(new Date());		
						chngPO.setCreateBy(logonUser.getUserId());
						dao.insert(chngPO);
					}
				}
				act.setOutData("returnValue", 1);
				act.setForword(VehicleDispatchInitUrl);
			}
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "调拨申请：提交");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * FUNCTION		:	调拨审核页面初始化(OEM)
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-5-31
	 */
	public void vehicleDispatchCheckOEMInit(){
		AclUserBean logonUser = null;
		try {
			ActionContextExtend atx = (ActionContextExtend) ActionContext.getContext();
			String reqURL = atx.getRequest().getContextPath();
			if("/CVS-SALES".equals(reqURL.toUpperCase())){
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
			}
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			act.setForword(vehicleDispatchCheckOEMInit);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "调拨申请页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	} 
	/**
	 * FUNCTION		:	调拨审核页面:查询可审批的调拨列表
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-6-1
	 */
	public void vehicleDispatchCheckList(){
		AclUserBean logonUser = null;
		try {
			RequestWrapper request = act.getRequest();
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			Long orgId = logonUser.getOrgId() ;
			String orgType = logonUser.getDutyType() ;
			String outDealerCode = CommonUtils.checkNull(request.getParamValue("outDealerCode"));	//调出经销商
			String inDealerCode = CommonUtils.checkNull(request.getParamValue("inDealerCode"));		//调入经销商
			String materialCode = CommonUtils.checkNull(request.getParamValue("materialCode"));		//物料组
			String vin = CommonUtils.checkNull(request.getParamValue("vin"));						//VIN
			
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
			PageResult<Map<String, Object>> ps = null ;
			if (orgType.equals(Constant.DUTY_TYPE_COMPANY.toString())) {
				ps = VehicleDispatchDAO.getVehicleDispatchCheckListA(outDealerCode, inDealerCode, materialCode, vin, Constant.PAGE_SIZE, curPage);
			} else {
				Long poseId = logonUser.getPoseId() ;
				ps = VehicleDispatchDAO.getVehicleDispatchCheckListB(poseId, orgId.toString(),outDealerCode, inDealerCode, materialCode, vin, Constant.PAGE_SIZE, curPage);
			}
			// PageResult<Map<String, Object>> ps = VehicleDispatchDAO.getVehicleDispatchCheckList(outDealerCode, inDealerCode, materialCode, vin, Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
			
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "调拨审核页面:查询可审批的调拨列表");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	} 
	/**
	 * FUNCTION		:	调拨审核页面:提交审核结果
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-6-1
	 */
	public void vehicleDispatchCheckSubmit(){
		AclUserBean logonUser = null;
		try {
			RequestWrapper request = act.getRequest();
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String transferIds = request.getParamValue("transferIdsA");
			String[] transferIds__ = transferIds.split(",");
			String checkStatus = CommonUtils.checkNull(request.getParamValue("checkStatus"));//审核结果：1:同意；0：驳回
			String checkDesc = CommonUtils.checkNull(request.getParamValue("checkDesc"));	 //审批意见
			/*if (null != checkDesc && !"".equals(checkDesc)) {
				checkDesc = new String(checkDesc.getBytes("ISO-8859-1"),"GB2312");
			}*/
			if (null != transferIds__ && transferIds__.length>0) {
				for (int j = 0; j < transferIds__.length; j++) {
					
					//1.更新“调拨申请表(TT_VS_VEHICLE_TRANSFER)”审核状态
					TtVsVehicleTransferPO temptTransferPO = new TtVsVehicleTransferPO();
					temptTransferPO.setTransferId(Long.parseLong(transferIds__[j]));
					//查询调出方id，判断是否是经销商
					List transferList = dao.select(temptTransferPO);
					Long outDealerId = ((TtVsVehicleTransferPO)transferList.get(0)).getOutDealerId();
					TmDealerPO tmDealerPO = new TmDealerPO();
					tmDealerPO.setDealerId(outDealerId);
					List dealerList = dao.select(tmDealerPO);
					Integer dealerType = ((TmDealerPO)dealerList.get(0)).getDealerType();
					
					
					TtVsVehicleTransferPO valueTransferPO = new TtVsVehicleTransferPO();
					if (null != checkStatus && "1".equals(checkStatus)) {
						valueTransferPO.setCheckStatus(Constant.DISPATCH_STATUS_03);//审核通过
						if (dealerType == Constant.DEALER_TYPE_JSZX) {
							List<Object> ins = new LinkedList<Object>();
							ins.add(transferIds__[j]);
							List<Integer> outs = new LinkedList<Integer>();
							dao.callProcedure("P_VEHICLE_TRANSFERDATA_TO_ERP", ins, outs);
						}
					}else{
						valueTransferPO.setCheckStatus(Constant.DISPATCH_STATUS_04);//驳回
					}
					dao.update(temptTransferPO, valueTransferPO);
					//2.向TT_VS_VEHICLE_TRANSFER_CHK写入审核信息
					TtVsVehicleTransferChkPO chkPO = new TtVsVehicleTransferChkPO();
					Long checkId = Long.parseLong(SequenceManager.getSequence(""));
					chkPO.setCheckId(checkId);								//审核ID
					chkPO.setTransferId(Long.parseLong(transferIds__[j]));	//调拨ID
					chkPO.setCheckOrgId(logonUser.getOrgId());				//审核部门
					chkPO.setCheckPositionId(logonUser.getPoseId());		//审核职位
					chkPO.setCheckUserId(logonUser.getUserId());			//审核人
					if (null != checkDesc && !"".equals(checkDesc)) {
						chkPO.setCheckDesc(checkDesc.trim());				//审核描述
					}
					if (null != checkStatus && "1".equals(checkStatus)) {
						chkPO.setCheckStatus(Constant.DISPATCH_STATUS_03);	//审核结果:审核通过
					}else{
						chkPO.setCheckStatus(Constant.DISPATCH_STATUS_04);	//审核结果:驳回
					}
					chkPO.setCreateBy(logonUser.getUserId());
					chkPO.setCreateDate(new Date());
					dao.insert(chkPO);
					
					
					List tranList = dao.select(temptTransferPO);
					//3.根据“调拨申请表TT_VS_VEHICLE_TRANSFER”更新TM_VEHICLE的dealerId
					if (null != checkStatus && "1".equals(checkStatus)) {
						if (null != tranList && tranList.size()>0) {
							Long inDealerId = ((TtVsVehicleTransferPO)tranList.get(0)).getInDealerId();	//调入经销商ID
							Long vehicleId = ((TtVsVehicleTransferPO)tranList.get(0)).getVehicleId();	//调拨车辆ID
							TmVehiclePO tempVehiclePO = new TmVehiclePO();
							tempVehiclePO.setVehicleId(vehicleId);
							TmVehiclePO valueVehiclePO = new TmVehiclePO();
							valueVehiclePO.setVehicleId(vehicleId) ;
							valueVehiclePO.setDealerId(inDealerId);
							valueVehiclePO.setStorageDate(new Date()) ;
							valueVehiclePO.setVehicleArea("");
							dao.update(tempVehiclePO, valueVehiclePO);
						}
					}
					
					
					//4.向TT_VS_VHCL_CHNG写入变更日志
					
					TtVsVhclChngPO chngPO = new TtVsVhclChngPO();
					Long vhclChangeId = Long.parseLong(SequenceManager.getSequence(""));
					chngPO.setVhclChangeId(vhclChangeId);				//改变序号
					chngPO.setVehicleId(((TtVsVehicleTransferPO)tranList.get(0)).getVehicleId());//车辆ID
					chngPO.setOrgType(logonUser.getOrgType());			//组织类型
					chngPO.setOrgId(logonUser.getOrgId());				//组织ID
					if (null != checkStatus && "1".equals(checkStatus)) {//经销商ID
						if (null != tranList && tranList.size()>0) {
							chngPO.setDealerId(((TtVsVehicleTransferPO)tranList.get(0)).getInDealerId());
						}
					}else{
						if (null != tranList && tranList.size()>0) {
							Long vehicleId = ((TtVsVehicleTransferPO)tranList.get(0)).getVehicleId();
							TmVehiclePO vehiclePO = new TmVehiclePO();
							vehiclePO.setVehicleId(vehicleId);
							List vehicleList = dao.select(vehiclePO);
							Long dealerId = ((TmVehiclePO)vehicleList.get(0)).getDealerId();
							chngPO.setDealerId(dealerId);
						}
					}
					
					
					chngPO.setChangeCode(Constant.STORAGE_CHANGE_TYPE);	//改变类型:库存状态更改
					if (null != checkStatus && "1".equals(checkStatus)) {
						chngPO.setChangeName(Constant.STORAGE_CHANGE_TYPE_06+"");//改变名称:调拨审批通过
					}else{
						chngPO.setChangeName(Constant.STORAGE_CHANGE_TYPE_07+"");//改变名称:调拨审批驳回
					}
					chngPO.setChangeDate(new Date());					//改变时间
					if (null != checkDesc && !"".equals(checkDesc)) {
						chngPO.setChangeDesc(checkDesc.trim());  		//改变描述
					}
					chngPO.setCreateDate(new Date());		
					chngPO.setCreateBy(logonUser.getUserId());
					dao.insert(chngPO);
				}
			}
			act.setOutData("returnValue", 1);
			act.setForword(vehicleDispatchCheckOEMInit);
		}  catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "调拨审核页面:提交审核结果");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
		
	}
	
	
	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}

}
